package com.raptor.trustworthy.task;

import com.raptor.trustworthycore.TrustworthyCoreConfig;
import com.raptor.trustworthycore.listener.TrustwothyPreparedListener;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.system.ApplicationPidFileWriter;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableAutoConfiguration
@MapperScan(value = {"com.raptor.trustworthy.task.mapper"})
@ComponentScan(basePackageClasses = {TrustworthyCoreConfig.class, TrustworthyTaskApplication.class})
@EnableTransactionManagement
@EnableScheduling
public class TrustworthyTaskApplication extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return configureApplication(builder);
  }

  private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
    return builder
        .sources(TrustworthyTaskApplication.class)
        .listeners(new TrustwothyPreparedListener())
        .listeners(new ApplicationPidFileWriter());
  }

  public static void main(String[] args) {
    configureApplication(new SpringApplicationBuilder()).run(args);
  }
}
